home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / INDENT3.ARJ / INDENT_G.H < prev    next >
C/C++ Source or Header  |  1992-08-04  |  10KB  |  290 lines

  1. /* Copyright (c) 1980 Regents of the University of California. All rights
  2.  * reserved.  The Berkeley software License Agreement specifies the terms and
  3.  * conditions for redistribution. 
  4.  *
  5.  * @(#)indent_globs.h      5.4 (Berkeley) 9/10/85 */
  6.  
  7. /*-
  8.   
  9.                           Copyright (C) 1976
  10.                                 by the
  11.                           Board of Trustees
  12.                                 of the
  13.                         University of Illinois
  14.   
  15.                          All rights reserved
  16.   
  17. FILE NAME:
  18.         indent_globs.h
  19.   
  20. PURPOSE:
  21.         This include file contains the declarations for all global variables
  22.         used in indent.
  23.   
  24. GLOBALS:
  25.         The names of all of the variables will not be repeated here.  The 
  26.         declarations start on the next page.
  27.   
  28. FUNCTIONS:
  29.         None
  30. */
  31.  
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <stdlib.h>
  35. #ifdef __STDC__
  36. #include <stdarg.h>
  37. #else
  38. #include <varargs.h>
  39. #endif
  40.  
  41. #include "indent_codes.h"
  42.  
  43. #define BACKSLASH '\\'
  44. #define bufsize 600
  45. #define inp_bufs 600
  46. #define sc_size 5000
  47. #define label_offset 2
  48.  
  49. #ifndef STACK_SIZE
  50. #define STACK_SIZE 16
  51. #endif
  52.  
  53. #ifndef STACKS
  54. #define STACKS 64
  55. #endif
  56.  
  57. #define false 0
  58. #define true  1
  59.  
  60. #define NIL 0
  61.  
  62. FILE *input;            /* the fid for the input file */
  63. FILE *output;            /* the output file */
  64.  
  65. char labbuf[bufsize];        /* buffer for label */
  66. char *s_lab;            /* start ... */
  67. char *e_lab;            /* .. and end of stored label */
  68.  
  69. char codebuf[bufsize];        /* buffer for code section */
  70. char *s_code;            /* start ... */
  71. char *e_code;            /* .. and end of stored code */
  72.  
  73. char combuf[bufsize];        /* buffer for comments */
  74. char *s_com;            /* start ... */
  75. char *e_com;            /* ... and end of stored comments */
  76.  
  77. char in_buffer[inp_bufs];    /* input buffer */
  78. char *buf_ptr;            /* ptr to next character to be taken from
  79.                  * in_buffer */
  80. char *buf_end;            /* ptr to first after last char in in_buffer */
  81.  
  82. char save_com[sc_size];        /* input text is saved here when looking for
  83.                  * the brace after an if, while, etc */
  84. char *sc_end;            /* pointer into save_com buffer */
  85.  
  86. char *bp_save;            /* saved value of buf_ptr when taking input
  87.                  * from save_com */
  88. char *be_save;            /* similarly saved value of buf_end */
  89.  
  90. char token[bufsize];        /* the last token scanned */
  91.  
  92. int blanklines_after_declarations;
  93. int blanklines_before_blockcomments;
  94. int blanklines_after_procs;
  95. int swallow_optional_blanklines;
  96. int n_real_blanklines;
  97. int prefix_blankline_requested;
  98. int postfix_blankline_requested;
  99. int break_comma;        /* when true and not in parens, break after a
  100.                  * comma */
  101. int btype_2;            /* when true, brace should be on same line as
  102.                  * if, while, etc */
  103. float case_ind;            /* indentation level to be used for a "case
  104.                  * n:" */
  105. int code_lines;            /* count of lines with code */
  106. int had_eof;            /* set to true when input is exhausted */
  107. int line_no;            /* the current line number. */
  108. int max_col;            /* the maximum allowable line length */
  109. int pointer_as_binop;        /* when true, "->" is treated as a binary
  110.                  * operator (giving, e.g., "p -> f") */
  111. int verbose;            /* when true, non-essential error messages
  112.                  * are printed */
  113. int cuddle_else;        /* true if else should cuddle up to '}' */
  114. int star_comment_cont;        /* true iff comment continuation lines should
  115.                  * have stars at the beginning of each line. */
  116. int comment_delimiter_on_blankline;
  117. int troff;            /* true iff were generating troff input */
  118. int procnames_start_line;    /* if true, the names of procedures being
  119.                  * defined get placed in column 1 (ie. a
  120.                  * newline is placed between the type of the
  121.                  * procedure and its name) */
  122. int proc_calls_space;        /* If true, procedure calls look like:
  123.                  * foo(bar) rather than foo (bar) */
  124. int format_col1_comments;    /* If comments which start in column 1 are to
  125.                  * be magically reformatted (just like
  126.                  * comments that begin in later columns) */
  127. int inhibit_formatting;        /* true if INDENT OFF is in effect */
  128. int suppress_blanklines;    /* set iff following blanklines should be
  129.                  * suppressed */
  130. int continuation_indent;    /* set to the indentation between the edge of
  131.                  * code and continuation lines */
  132. int lineup_to_parens;        /* if true, continued code within parens will
  133.                  * be lined up to the open paren */
  134. int block_comment_max_col;
  135.  
  136. /* if true then a built-in  profile is set up */
  137. int gnu_format;
  138. int kr_format;
  139.  
  140. int tabsize;            /* size of a tab character */
  141. #define tabmask 0xfff8
  142. int format_comments;        /* don't format any comments */
  143.  
  144. struct parser_state {
  145.     int last_token;
  146.     int p_stack[STACKS];    /* this is the parsers stack */
  147.     int il[STACKS];        /* this stack stores indentation levels */
  148.     float cstk[STACKS];        /* used to store case stmt indentation levels */
  149.     int box_com;        /* set to true when we are in a "boxed"
  150.                  * comment. In that case, the first non-blank
  151.                  * char should be lined up with the / in /* */
  152.     int comment_delta, n_comment_delta;
  153.     int cast_mask;        /* indicates which close parens close off
  154.                  * casts */
  155.     int sizeof_mask;        /* indicates which close parens close off
  156.                  * sizeof''s */
  157.     int block_init;        /* true iff inside a block initialization */
  158.     int last_nl;        /* this is true if the last thing scanned was
  159.                  * a newline */
  160.     int in_or_st;        /* Will be true iff there has been a
  161.                  * declarator (e.g. int or char) and no left
  162.                  * paren since the last semicolon. When true,
  163.                  * a '{' is starting a structure definition
  164.                  * or an initialization list */
  165.     int bl_line;        /* set to 1 by dump_line if the line is blank */
  166.     int col_1;            /* set to true if the last token started in
  167.                  * column 1 */
  168.     int com_col;        /* this is the column in which the current
  169.                  * coment should start */
  170.     int com_ind;        /* the column in which comments to the right
  171.                  * of code should start */
  172.     int com_lines;        /* the number of lines with comments, set by
  173.                  * dump_line */
  174.     int dec_nest;        /* current nesting level for structure or
  175.                  * init */
  176.     int decl_com_ind;        /* the column in which comments after
  177.                  * declarations should be put */
  178.     int decl_on_line;        /* set to true if this line of code has part
  179.                  * of a declaration on it */
  180.     int i_l_follow;        /* the level to which ind_level should be set
  181.                  * after the current line is printed */
  182.     int in_decl;        /* set to true when we are in a declaration
  183.                  * stmt.  The processing of braces is then
  184.                  * slightly different */
  185.     int in_stmt;        /* set to 1 while in a stmt */
  186.     int ind_level;        /* the current indentation level */
  187.     int ind_size;        /* the size of one indentation level */
  188.     int ind_stmt;        /* set to 1 if next line should have an extra
  189.                  * indentation level because we are in the
  190.                  * middle of a stmt */
  191.     int last_u_d;        /* set to true after scanning a token which
  192.                  * forces a following operator to be unary */
  193.     int leave_comma;        /* if true, never break declarations after
  194.                  * commas */
  195.     int ljust_decl;        /* true if declarations should be left
  196.                  * justified */
  197.     int out_coms;        /* the number of comments processed, set by
  198.                  * pr_comment */
  199.     int out_lines;        /* the number of lines written, set by
  200.                  * dump_line */
  201.     int p_l_follow;        /* used to remember how to indent following
  202.                  * statement */
  203.     int paren_level;        /* parenthesization level. used to indent
  204.                  * within stmts */
  205.     short paren_indents[STACKS];/* column positions of each paren */
  206.     int pcase;            /* set to 1 if the current line label is a
  207.                  * case.  It is printed differently from a
  208.                  * regular label */
  209.     int search_brace;        /* set to true by parse when it is necessary
  210.                  * to buffer up all info up to the start of a
  211.                  * stmt after an if, while, etc */
  212.     int unindent_displace;    /* comments not to the right of code will be
  213.                  * placed this many indentation levels to the
  214.                  * left of code */
  215.     int use_ff;            /* set to one if the current line should be
  216.                  * terminated with a form feed */
  217.     int want_blank;        /* set to true when the following token
  218.                  * should be prefixed by a blank. (Said
  219.                  * prefixing is ignored in some cases.) */
  220.     int else_if;        /* True iff else if pairs should be handled
  221.                  * specially */
  222.     int decl_indent;        /* column to indent declared identifiers to */
  223.     int its_a_keyword;
  224.     int sizeof_keyword;
  225.     int dumped_decl_indent;
  226.     float case_indent;        /* The distance to indent case labels from
  227.                  * the switch statement */
  228.     int in_parameter_declaration;
  229.     int indent_parameters;
  230.     int tos;            /* pointer to top of stack */
  231.     char procname[100];        /* The name of the current procedure */
  232.     int just_saw_decl;
  233. } ps;
  234.  
  235. int ifdef_level;
  236. extern struct parser_state state_stack[STACK_SIZE];
  237. extern struct parser_state match_state[STACK_SIZE];
  238.  
  239. #ifdef __STDC__
  240. # define        PROTO(s) s
  241. #else
  242. # define PROTO(s) ()
  243. #endif
  244.  
  245.  
  246. /* args.c */
  247. int set_profile PROTO((void));
  248. void scan_profile PROTO((FILE * f));
  249. int eqin PROTO((char *s1, char *s2));
  250. void set_defaults PROTO((void));
  251. void set_option PROTO((char *arg));
  252.  
  253. /* doindent.c */
  254. void switch_on PROTO((int type_code));
  255.  
  256. /* dopreesc.c */
  257. void dopreesc PROTO((void));
  258.  
  259. /* indent.c */
  260. void main PROTO((int argc, char **argv));
  261. void dosomething PROTO((void));
  262. void bakcopy PROTO((void));
  263. void cleanup PROTO((int ret));
  264.  
  265. /* io.c */
  266. void dump_line PROTO((void));
  267. int compute_code_target PROTO((void));
  268. int compute_label_target PROTO((void));
  269. void fill_buffer PROTO((void));
  270. int pad_output PROTO((int current, int target));
  271. int count_spaces PROTO((int current, char *buffer));
  272. #ifndef __STDC__
  273. void diag();
  274. #else
  275. void diag(int level, char *msg,...);
  276. #endif
  277.  
  278. /* lexi.c */
  279. enum codes lexi PROTO((void));
  280. void addkey PROTO((char *key, enum rwcodes val));
  281.  
  282. /* parse.c */
  283. void parse PROTO((int tk));
  284. void reduce PROTO((void));
  285.  
  286. /* pr_comme.c */
  287. void pr_comment PROTO((void));
  288.  
  289. #undef PROTO
  290.